#Install a package for a balance check
devtools::install_github("JaehyunSong/BalanceR")
library(BalanceR)

#Data for a Balance Check
bes_w22_balance <- bes_w22 |>
  mutate(ctr_gender=as_factor(gender),
         ctr_education=as_factor(p_edlevel),
         ctr_income=as_factor(p_gross_personal),
         white=ifelse(p_ethnicity==1,1L,0L),
         disability=ifelse(p_disability<=2,1L,0L),
         ctr_unemployed=ifelse(workingStatus==4,1L,0L)) |> 
  filter(date_diff>=-7,date_diff<=6) |> mutate(
    Age=age,Gender=gender,Education=p_edlevel,Income=p_gross_personal,
    Unemployment=ctr_unemployed,
    White=white,Disability=disability)

#Balance Check. Figure D1
balance <- BalanceR(data = bes_w22_balance, group = treatment,
                    cov = c(Age,Gender,Education,Income,
                          Unemployment, White,Disability)) |> 
  plot(point.size = 8, text.size = 24,color = FALSE)
balance
